//
//  PhotoAttestationViewController.m
//  Molian
//
//  Created by 小蚕科技 on 15/6/2.
//  Copyright (c) 2015年 xiaocan. All rights reserved.
//

#import "PhotoAttestationViewController.h"
#import <FSMediaPicker.h>//照片选择

@interface PhotoAttestationViewController ()<FSMediaPickerDelegate>
@property (nonatomic, strong)UIImageView *headImageView;
@end

@implementation PhotoAttestationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"照片认证";
    self.view.backgroundColor =  APPCOLORBACKGROUNDCOLOR(1);
    NSString *str = @"请手持写有“口袋恋人”字样的纸,按照左下图示姿势拍一张认证照片吧。";
    NSString *ps =@"PS: 此照片仅用于审核,不会作为你的头像使用,口袋恋人不会公开该照片。";
    
    UIView *blackView =[[UIView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight, DeviceWidth, DeviceWidth/320*250)];
    blackView.backgroundColor =[UIColor whiteColor];
    [self.view addSubview:blackView];
    
    UILabel *redLabel =[[UILabel alloc] initWithFrame:CGRectMake(40, 40, DeviceWidth-80, 40)];
    redLabel.font = [UIFont fontWithName:FontName size:14];
    redLabel.text = str;
    redLabel.numberOfLines  = 0;
    redLabel.textColor = APPCOLOR(1);
    [blackView addSubview:redLabel];
    
    UILabel *remarks =[[UILabel alloc] initWithFrame:CGRectMake(40, 80, DeviceWidth-80, 40)];
    remarks.font = [UIFont fontWithName:FontName size:14];
    remarks.text = ps;
    remarks.numberOfLines  = 0;
    remarks.textColor = RGBA(133, 133, 133, 1);
    [blackView addSubview:remarks];
    
    for(int i = 0;i < 2; i++){
        UIImageView *headView =[[UIImageView alloc] initWithFrame:CGRectMake(60 + i*((DeviceWidth-160)/2+40), 150, (DeviceWidth-160)/2, (DeviceWidth-160)/2)];
        headView.layer.cornerRadius = 4;
        headView.layer.masksToBounds = YES;
        if (i == 0) {
            headView.image = ReadImageFromBundle(@"mine_more_apply-for-lover_photo_img", @"png");
        }else{
            self.headImageView = headView;
            headView.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickImage:)];
            [headView addGestureRecognizer:tap];
            
            if (self.selectImage) {
                headView.image = self.selectImage;
            }else{
                   headView.image = [UIImage imageNamed:@"me_placeholder_jia_ing"];
            }
          
        }
       
        [blackView addSubview:headView];
    }
    
    
    UIButton *confirmBt =[UIButton buttonWithType:UIButtonTypeCustom];
    confirmBt.frame = CGRectMake(50, kNavigationBarHeight+DeviceWidth/320*250+20, DeviceWidth-100, 40);
    confirmBt.layer.cornerRadius = 20;
    confirmBt.layer.masksToBounds = YES;
    [confirmBt setTitle:@"确定" forState:UIControlStateNormal];
    confirmBt.titleLabel.font = [UIFont fontWithName:FontName size:14];
    [confirmBt addTarget:self action:@selector(cliclConfir) forControlEvents:UIControlEventTouchUpInside];
    confirmBt.backgroundColor = APPCOLOR(1);
    [self.view addSubview:confirmBt];
    // Do any additional setup after loading the view.
}
- (void)cliclConfir
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)clickImage:(UITapGestureRecognizer *)tap
{
    FSMediaPicker *mediaPicker = [[FSMediaPicker alloc] init];
    mediaPicker.mediaType = FSMediaTypePhoto;
    mediaPicker.editMode = FSEditModeStandard;
    mediaPicker.delegate = self;
    [mediaPicker showFromView:self.view];
}
- (void)mediaPicker:(FSMediaPicker *)mediaPicker didFinishWithMediaInfo:(NSDictionary *)mediaInfo
{
    // 保存新背景
    float kCompressionQuality = 0.3;
    NSData *imgData = UIImageJPEGRepresentation(mediaInfo.editedImage, kCompressionQuality);
    if ([self.delegate respondsToSelector:@selector(byValueAVFile:andUserAttestationImage:)]) {
        [self.delegate byValueAVFile:[AVFile fileWithName:@"background.png" data:imgData] andUserAttestationImage:mediaInfo.editedImage];
    }
    self.headImageView.image = mediaInfo.editedImage;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
